#include "EvaluatorDataDepthReader.h"
#include "reader/NCoreReader.h"
#include "helper/NCorePathHelper.h"

class reader::EvaEnvDataDepthReaderPrivate 
{
public:
};

reader::EvaEnvDataDepthReader::EvaEnvDataDepthReader()
	: d(new EvaEnvDataDepthReaderPrivate)
{
}

reader::EvaEnvDataDepthReader::~EvaEnvDataDepthReader()
{
	delete d;
}

std::map<algobase::EvaluateEnvirDataType, std::map<std::string, darr::DimsArray<float>>> reader::EvaEnvDataDepthReader::readData() const
{
    std::map<algobase::EvaluateEnvirDataType, std::map<std::string, darr::DimsArray<float>>> result;
    std::map<std::string, darr::DimsArray<float>> dp_result;

    auto task_config = getTaskConfig();
    ncore::reader::Area area(
        task_config.mMinLongitude, task_config.mMaxLongitude,
        task_config.mMinLatitude, task_config.mMaxLatitude, 0.0, 20000);

    ncore::helper::PathHelper pathHelper;

    for (int i = task_config.mStartTime.mYear; i <= task_config.mEndTime.mYear; ++i) 
    {
        algobase::Date loop_date(i, 0, 0);

        std::string file_name = pathHelper.getDBDirPath() + "/dp/GEBCO_" + std::to_string(i) + ".nc";
        if (file_name.empty()) {
            return result;
        }

        ncore::reader::NCoreReaderResult<float> loop_read_result;
        ncore::reader::NCoreReader reader(file_name);
        bool read_exec_result = reader.readArea<float>(area, loop_read_result);
        if (!read_exec_result) {
            return result;
        }

        dp_result[loop_date.to_string()] = std::move(loop_read_result["elevation"]);
    }

    result[algobase::EEDT_Depth] = std::move(dp_result);
    return result;
}
